<template>
	<view class="container b-f">
		<!-- 顶部选项卡 -->
		<view class="swiper-tab dis-flex box-align-center flex-y-center">
			<block v-for="(item, index) in tabList" :key="index">
				<view class="swiper-tab-item" :class="{ on: dataType == item.value }" :data-current="item.value" @tap="swichNav">{{ item.text }}</view>
			</block>
		</view>
		<scroll-view :scroll-y="true" @scrolltolower="triggerDownLoad" :style="{ height: swiperHeight + 'px' }">
			<view class="widget-list" v-if="list.data.length">
				<view class="widget__detail dis-flex flex-x-between" v-for="(item, index) in list.data" :key="index">
					<view class="detail__left dis-flex flex-dir-column flex-x-around">
						<view class="detail__money f-30">提现 {{ item.money }}元</view>
						<view class="detail__time col-9 f-24">{{ item.create_time }}</view>
					</view>
					<view class="detail__right dis-flex flex-dir-column flex-x-center flex-y-center">
						<view :class="'detail__status f-28 ' + (item.apply_status == 20 || item.apply_status == 40 ? 'col-green' : 'col-m')">{{ applyStatus[item.apply_status] }}</view>
						<template v-if="item.apply_status == 30">
							<view class="detail__reason f-24" @tap="triggerReasonMsg" :data-reason="item.reject_reason">查看原因</view>
						</template>
					</view>
				</view>
				<!-- 没有更多 -->
				<view v-if="list.data.length && !isLoading && no_more" class="no-more f-30">亲, 没有更多了</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			applyStatus: [],
			isLoading: true,
			dataType: -1,
			page: 1,
			no_more: false,
			swiperHeight: null,
			list: { data: [] },
			tabList: []
		};
	},
	onLoad() {
		this.setSwiperHeight();
	},
	onShow() {
		// 获取提现明细列表
		this.getWithdrawList();
	},
	methods: {
		/**
		 * 设置swiper的高度
		 */
		setSwiperHeight() {
			// 获取系统信息(拿到屏幕宽度)
			let systemInfo = wx.getSystemInfoSync();
			let tapHeight = uni.upx2px(82); // tap高度
			this.swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
		},
		/**
		 * 获取提现明细列表
		 */
		getWithdrawList(isNextPage, page) {
			this.$get(
				this.$api.getUserDealerWithdrawLists,
				{
					status: this.dataType,
					page: page || 1
				},
				res => {
					// 创建页面数据
					const data = this.createData(res.data, isNextPage);
					this.applyStatus = data.applyStatus;
					this.isLoading = data.isLoading;
					this.list = data.list;
					this.tabList = data.tabList;
				}
			);
		},
		/**
		 * 创建页面数据
		 */
		createData(data, isNextPage) {
			data['isLoading'] = false;
			// 列表数据
			let dataList = this.list;
			if (isNextPage == true && typeof dataList !== 'undefined') {
				data.list.data = dataList.data.concat(data.list.data);
			}
			// 导航栏数据
			data['tabList'] = [
				{
					value: -1,
					text: '全部'
				},
				{
					value: 10,
					text: '审核中'
				},
				{
					value: 20,
					text: '审核通过'
				},
				{
					value: 40,
					text: '已打款'
				},
				{
					value: 30,
					text: '驳回'
				}
			];
			// 审核状态
			data['applyStatus'] = {};
			data['tabList'].forEach(function(item) {
				data['applyStatus'][item.value] = item.text;
			});
			return data;
		},
		/**
		 * 点击tab切换
		 */
		swichNav(e) {
			let current = e.target.dataset.current;
			if (this.dataType == current) {
				return false;
			}
			this.dataType = current;
			this.list = { data: [] };
			this.page = 1;
			this.no_more = false;
			this.isLoading = true;
			this.$nextTick(() => {
				this.getWithdrawList();
			});
		},
		/**
		 * 查看驳回原因
		 */
		triggerReasonMsg: function(e) {
			uni.showModal({
				title: '驳回理由',
				content: e.currentTarget.dataset.reason,
				showCancel: false
			});
		}
	}
};
</script>

<style>
page {
	background: #fff;
}

/* 选项卡 */

.swiper-tab {
	width: 100%;
	text-align: center;
	height: 80rpx;
	background-color: #fff;
	border-bottom: 1px solid #eee;
}

.swiper-tab .swiper-tab-item {
	width: 33.333333%;
	height: 100%;
	font-size: 28rpx;
	color: #777;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	border-bottom: 2px solid #ffffff00;
}

.swiper-tab .on {
	color: #786cff;
	border-bottom: 2px solid #786cff;
}

/* 设置scroll-view容器高度 */

.widget-list,
.yoshop-notcont {
	height: 100.1%;
}

/* 提现明细列表 */

.widget-list {
	padding: 10rpx 20rpx 40rpx 20rpx;
	box-sizing: border-box;
}

.widget__detail {
	padding: 20rpx 15rpx;
	box-sizing: border-box;
	font-size: 28rpx;
	border-bottom: 1rpx solid #e7e7e7;
}

.widget__detail .detail__money {
	font-size: 30rpx;
	margin-bottom: 12rpx;
}

.widget__detail .detail__reason {
	margin-top: 15rpx;
	color: #8e84fc;
}
</style>
